package test.teacher.common.utils;





import java.beans.PropertyVetoException;
import java.io.Closeable;
import java.sql.*;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import com.mysql.jdbc.Driver;


public class DBUtils {
    private static String driver = "com.mysql.jdbc.Driver";
    private static String url = "jdbc:mysql://localhost:3306/jtb";
    private static String root = "root";
    private static String password = "77";
    public static Connection getConnection() throws PropertyVetoException, SQLException, ClassNotFoundException {
        /*ComboPooledDataSource dataSource = new ComboPooledDataSource();
        dataSource.setJdbcUrl(url);
        dataSource.setDriverClass(driver);
        dataSource.setUser(root);
        dataSource.setPassword(password);*/
        Class.forName("com.mysql.jdbc.Driver");
        Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/jtb?user=root&password=77&serverTimezone=UTC");
        return  con;
    }

    public static Connection getConnection2() throws PropertyVetoException, SQLException, ClassNotFoundException {
        ComboPooledDataSource dataSource = new ComboPooledDataSource();
        dataSource.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/jtb?serverTimezone=UTC");
        dataSource.setDriverClass(driver);
        dataSource.setUser(root);
        dataSource.setPassword(password);
        Connection con = dataSource.getConnection();
        return  con;
    }

    public static void close(ResultSet resultSet, PreparedStatement preparedStatement, Connection connection) throws SQLException {
        if (resultSet != null) {
            resultSet.close();
        }
        if (preparedStatement != null) {
            preparedStatement.close();
        }
        if (connection != null) {
            connection.close();
        }
    }
}
